package com.example.rabbitmq.demo01.demo02;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class RabbitMqUtils {
    static Channel getChannel() throws IOException, TimeoutException {
        //1、创建一个连接工厂
        ConnectionFactory factory = new ConnectionFactory();

        //2、设置工厂ip，即rabbitmq服务所在的地址
        factory.setHost("127.0.0.1");
        //3、设置rabbitmq的用户名
        factory.setUsername("guest");
        //4、设置rabbitmq的密码
        factory.setPassword("guest");

        //5、创建连接
        Connection connection = factory.newConnection();

        //6、获取连接中的信道
        Channel channel = connection.createChannel();

        return channel;
    }
}
